package service.imp;

import base.StatusCode;
import dao.CourseContentDao;
import dao.imp.CourseContentDaoImpl;
import pojo.Course;
import pojo.Course_Lesson;
import pojo.Course_Section;
import service.CourseContentService;
import utils.DateUtils;

import java.util.List;

public class CourseContentServiceImpl  implements CourseContentService {

    CourseContentDao contentDao = new CourseContentDaoImpl();

    @Override
    public List<Course_Section> findSectionAndLessonByCourseId(int courseId) {
        List<Course_Section> sections = contentDao.findSectionAndLessonByCourseId(courseId);
        return sections;
    }

    @Override
    public Course findCourseByCourseId(int courseId) {
        return contentDao.findCourseByCourseId(courseId);
    }

    @Override
    public String saveSection(Course_Section section) {
        section.setStatus(2);

        String dateFormart = DateUtils.getDateFormart();
        section.setCreate_time(dateFormart);
        section.setUpdate_time(dateFormart);


        int i = contentDao.saveSection(section);

        if (i>0){
            String result = StatusCode.SUCCESS.toString();

            return result;
        }else {
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }

    @Override
    public String updateSection(Course_Section section) {

        String dateFormart = DateUtils.getDateFormart();
        section.setUpdate_time(dateFormart);

        int i = contentDao.updateSection(section);
        if (i>0){
            String result = StatusCode.SUCCESS.toString();

            return result;
        }else {
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }

    @Override
    public String updateSectionStatus(int id, int status) {
        int i = contentDao.updateSectionStatus(id, status);
        if (i>0){
            String result = StatusCode.SUCCESS.toString();
            return result;
        }else {
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }

    @Override
    public Course_Section findSectionBySectionId(int sectionId) {
        return contentDao.findSectionBySectionId(sectionId);
    }

    @Override
    public String saveLesson(Course_Lesson lesson) {
        lesson.setStatus(2);

        String dateFormart = DateUtils.getDateFormart();
        lesson.setCreate_time(dateFormart);
        lesson.setUpdate_time(dateFormart);

        int i = contentDao.saveLesson(lesson);

        if (i>0){
            String result = StatusCode.SUCCESS.toString();

            return result;
        }else {
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }

    @Override
    public String updateLesson(Course_Lesson lesson) {
        String dateFormart = DateUtils.getDateFormart();
        lesson.setUpdate_time(dateFormart);

        int i = contentDao.updateLesson(lesson);
        if (i>0){
            String result = StatusCode.SUCCESS.toString();

            return result;
        }else {
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }


}
